/**
 * Created by Haibin on 2017/8/25.
 */
    function loadpage(){
        if (document.cookie.length>0){
            var username=getCookie("username")
            if ($("title").text().indexOf(username) < 0){
                location.href="/login";
            }
        }
        else{
           location.href="/login";
        }
    }
    function getCookie(cookie_name)
    {
        var allcookies = document.cookie;
        var cookie_pos = allcookies.indexOf(cookie_name);   //索引的长度
        // 如果找到了索引，就代表cookie存在，
        // 反之，就说明不存在。
        if (cookie_pos != -1)
        {
            // 把cookie_pos放在值的开始，只要给值加1即可。
            cookie_pos += cookie_name.length + 1;      //这里容易出问题，所以请大家参考的时候自己好好研究一下
            var cookie_end = allcookies.indexOf(";", cookie_pos);
            if (cookie_end == -1)
            {
                cookie_end = allcookies.length;
            }
            var value = unescape(allcookies.substring(cookie_pos, cookie_end));         //这里就可以得到你想要的cookie的值了。。。
        }
        return value;
    }
    function changepage(dom){
        var username=getCookie("username");
        if (username===undefined){
            location.href="/login";
            return;
        }
        var curpage;
        var pagetotal;
        var count=parseInt($("#count").attr("value"))
        if (dom.getAttribute("class")==="form-control"){
            pagetotal=dom.options[dom.selectedIndex].value
            curpage=1;
        }else {
            curpage = dom.getAttribute("value")
            pagetotal = $("#curtotal")[0].options[$("#curtotal")[0].selectedIndex].value
        }
        switch (curpage) {
            case "up":
                curpage = parseInt($("#page")[0].value) - 1;
                if (curpage < 1) {
                    curpage = 1
                    return;
                }
                break;
            case "next":
                curpage = parseInt($("#page")[0].value) + 1;
                if (curpage > count) {
                    curpage = count
                    return;
                }
                break;
            case null:
                curpage = parseInt($("#gopage")[0].value);
                if (curpage > count) {
                    curpage = count
                    alert("超出总页数，请重新输入")
                    return;
                }
                break;
        }
        $.ajax({
            type:"Post",
            url:'/my_test/testpage',
            data:{
                "curpage":curpage,
                "pagetotal":pagetotal,
            },
            async: false,
            error: function(result) {
                alert(result);
            },
            success: function(result) {
                $("#dataTable").html(result)
                $("#curtotal")[0].value=pagetotal
            }
            });
        return false;
    }